package com.eveinfo.display.setting;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.eveinfo.EveInfo;
import com.eveinfo.R;
import com.eveinfo.tools.EveInfoPreferences;
import com.eveinfo.tools.Setting;

public class SettingCacheView extends Activity {
	static final int DIALOG_ADDPILOT1 = 0;
	static final int DIALOG_ADDPILOT2 = 1;
	static final int DIALOG_EDITPILOT = 2;
	static final int DIALOG_DOWNLOAD = 3;
	static final int DIALOG_UNZIP = 4;

	private final Activity activity;
	private final EveInfoPreferences preferences;

	public SettingCacheView() {
		this.activity = this;
		this.preferences = EveInfo.getPreferences();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.settingcache);

		CheckBox cacheEnableCB = (CheckBox) findViewById(R.id.CBSettingCacheEnable);
		cacheEnableCB.setChecked(preferences.isEnableCache());
		cacheEnableCB.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				preferences.setEnableCache(isChecked);

			}
		});

		CheckBox cacheOnlyCB = (CheckBox) findViewById(R.id.CBSettingCacheOnly);
		cacheOnlyCB.setChecked(preferences.isCacheOnly());
		cacheOnlyCB.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				preferences.setCacheOnly(isChecked);
			}
		});

		Button deleteCacheB = (Button) findViewById(R.id.BSettingCacheDelete);
		deleteCacheB.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Setting.deleteCacheFiles(activity);
			}
		});

		Button deletePlannersB = (Button) findViewById(R.id.BSettingPlannersDelete);
		deletePlannersB.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Setting.deletePlannersFiles(activity);
			}
		});
	}

}